home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-11-08 | 7.5 KB | 269 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: HelloSel.cpp
- // Release Version: $ 1.0d11 $
- //
- // Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Hello.hpp"
-
- #ifndef HELLOSEL_H
- #include "HelloSel.h"
- #endif
-
- #ifndef HELLOPRT_H
- #include "HelloPrt.h"
- #endif
-
- #ifndef HELLODEF_H
- #include "HelloDef.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWUTIL_H
- #include "FWUtil.h"
- #endif
-
- // ----- OS Includes -----
-
- #ifndef FWBARRAY_H
- #include "FWBArray.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSUSINK_H
- #include "FWSUSink.h"
- #endif
-
- #ifndef FWSTREAM_H
- #include "FWStream.h"
- #endif
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
- #include <Drag.h>
- #endif
-
- //========================================================================================
- // Runtime information
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment odfhello
- #endif
-
- //========================================================================================
- // Constants
- //========================================================================================
-
- const ODPropertyName kHelloPropText = "Hello:Property:Text";
-
- //========================================================================================
- // CLASS CHelloSelection
- //========================================================================================
-
- //---------------------------------------------------------------------------------------
- // CHelloSelection constructor
- //---------------------------------------------------------------------------------------
-
- CHelloSelection::CHelloSelection(Environment* ev, CHelloPart* helloPart) :
- FW_CSelection(ev, FALSE, FALSE),
- fHelloPart(helloPart)
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CHelloSelection destructor
- //---------------------------------------------------------------------------------------
-
- CHelloSelection::~CHelloSelection()
- {
- }
-
- //---------------------------------------------------------------------------------------
- // CHelloSelection::CloseSelection
- //---------------------------------------------------------------------------------------
-
- void CHelloSelection::CloseSelection(Environment* ev)
- {
- // Nothing to do
- }
-
- //---------------------------------------------------------------------------------------
- // CHelloSelection::ClearSelection
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CHelloSelection::ClearSelection(Environment* ev)
- {
- // Empty the currently selected string
- fHelloPart->ClearTextData();
- fHelloPart->PartChanged(ev);
- return TRUE;
- }
-
- //---------------------------------------------------------------------------------------
- // CHelloSelection::IsEmpty
- //---------------------------------------------------------------------------------------
-
- FW_Boolean CHelloSelection::IsEmpty(Environment* ev) const
- {
- // Is the current string empty?
- return (fHelloPart->GetTextData().GetLength() == 0);
- }
-
- //---------------------------------------------------------------------------------------
- // CHelloSelection::SelectAll
- //---------------------------------------------------------------------------------------
-
- void CHelloSelection::SelectAll(Environment* ev)
- {
- // Not applicable
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloSelection::DoExternalizeSelection
- //----------------------------------------------------------------------------------------
-
- void CHelloSelection::DoExternalizeSelection(Environment* ev,
- ODStorageUnit* destinationSU,
- FW_CCloneInfo* cloneInfo)
- {
- // Get the current selection string
- FW_CString255 string(fHelloPart->GetTextData());
-
- // Write the string to the storage unit, in the part's content format
- FW_CStorageUnitSink suSink(destinationSU, kODPropContents, CHelloPart::kPartKind);
- FW_CWritableStream archive(&suSink);
- unsigned long stringCount = 1;
-
- archive << stringCount;
- FW_CStringArchiver::Write(archive, string);
-
- #ifdef FW_BUILD_MAC
- // Also write the string in text format
- FW_SUAddPropValue(ev, destinationSU, kODPropContents, FW_CPart::gMacTEXTDataType);
- FW_CStorageUnitSink sink2(destinationSU, kODPropContents, FW_CPart::gMacTEXTDataType);
- FW_CWritableStream stream(&sink2);
- FW_Char buffer[256];
- string.Export((char*) &buffer);
- stream.Write(&buffer, string.GetByteLength());
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloSelection::DoInternalizeSelection
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloSelection::DoInternalizeSelection(Environment* ev,
- ODStorageUnit* sourceSU,
- FW_CCloneInfo* cloneInfo)
- {
- FW_UNUSED(cloneInfo);
-
- FW_Boolean internalized = FALSE;
- FW_CString255 string("");
-
- if (sourceSU->Exists(ev, kODPropContents, fHelloPart->GetPartKind(ev), 0))
- {
- if (this->Internalize1String(ev, sourceSU, string))
- {
- fHelloPart->SetTextData(string);
- internalized = TRUE;
- }
- }
- #ifdef FW_BUILD_MAC
- else if (sourceSU->Exists(ev, kODPropContents, FW_CPart::gMacTEXTDataType, 0)) // 'TEXT'
- {
- if (this->InternalizeText(ev, sourceSU, string))
- {
- fHelloPart->SetTextData(string);
- internalized = TRUE;
- }
- }
- #endif
-
- if (internalized)
- {
- // Notify interested parties
- fHelloPart->PartChanged(ev);
- }
-
- return internalized;
- }
-
- //------------------------------------------------------------------------------
- // CHelloSelection::Internalize1String
- //------------------------------------------------------------------------------
- FW_Boolean CHelloSelection::Internalize1String(Environment* ev, ODStorageUnit* storageUnit,
- FW_CString& newString)
- {
- short result = FALSE;
-
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fHelloPart->GetPartKind(ev), 0, kODPosUndefined);
- if (storageUnit->GetSize(ev) != 0)
- {
- // Read one string from storage, if possible
- FW_CStorageUnitSink suSink(storageUnit, kODPropContents, fHelloPart->GetPartKind(ev));
- FW_CReadableStream archive(&suSink);
-
- unsigned long stringCount = 0;
- archive >> stringCount;
- if (stringCount > 0)
- {
- FW_CStringArchiver::Read(archive, newString);
- result = TRUE;
- }
- }
-
- return result;
- }
-
- //----------------------------------------------------------------------------------------
- // CHelloSelection::InternalizeText
- //----------------------------------------------------------------------------------------
-
- FW_Boolean CHelloSelection::InternalizeText(Environment* ev,
- ODStorageUnit* storageUnit,
- FW_CString& newString)
- {
- FW_Boolean result = FALSE;
-
- #ifdef FW_BUILD_MAC
- storageUnit->Focus(ev, kODPropContents, kODPosUndefined, FW_CPart::gMacTEXTDataType, 0, kODPosUndefined);
- unsigned long textSize = storageUnit->GetSize(ev);
- if (textSize > 0)
- {
- char buffer[256];
- if (textSize > 255)
- textSize = 255;
- FW_CByteArray byteArray;
- storageUnit->GetValue(ev, textSize, byteArray);
- byteArray.CopyBuffer(&buffer, textSize);
- newString.Append((const FW_Char*) &buffer, textSize);
- result = TRUE;
- }
- #endif
-
- return result;
- }
-
-